<?php

function noise_data_hour($selected_channels, $start_time, $end_time)
{
    if (isset($selected_channels))
    {
        $post_selected_channels = filter_input(INPUT_POST, 'selected_channels');

        if (isset($post_selected_channels)) 
        {
            $result = DBConnector::getInstance()->getNoiseDataHour(1,$post_selected_channels,$start_time, $end_time);
            echo json_encode($result);
        }
    }
}

// -> Acrescentei aqui
function noise_data_minute($selected_channels, $start_time, $end_time)
{
    if (isset($selected_channels))
    {
        $post_selected_channels = filter_input(INPUT_POST, 'selected_channels');

        if (isset($post_selected_channels)) 
        {
            $result = DBConnector::getInstance()->getNoiseDataMinute(1,$post_selected_channels,$start_time, $end_time);
            echo json_encode($result);
        }
    }
}

function wifi_data_count_hour($start_time, $end_time)
{
    $result = DBConnector::getInstance()->getWifiDataCountHour(1,$start_time, $end_time);
    echo json_encode($result);
}

// -> Acrescentei aqui
function wifi_data_count_minute($start_time, $end_time)
{
    $result = DBConnector::getInstance()->getWifiDataCountMinute(1,$start_time, $end_time);
    echo json_encode($result);
}

function wifi_data_count_all_by_day()
{
    $result = DBConnector::getInstance()->getWifiDataCountAllByDay(1);
    echo json_encode($result);
}

function noise_data_time_bounds()
{
    $result = DBConnector::getInstance()->getNoiseDataTimeBounds(1);
    echo json_encode($result);
}

function wifi_data_time_bounds()
{
    $result = DBConnector::getInstance()->getWifiDataTimeBounds(1);
    echo json_encode($result);
}

function get_cpes_by_zip($zip_code)
{
    $result = DBConnector::getInstance()->getCPEsByZip($zip_code);
    echo json_encode($result);
}

function get_juntas_by_zip($codigo_postal)
{
    $result = DBConnector::getInstance()->getJuntasByZip($codigo_postal);
    echo json_encode($result);
}

function get_num_trehsold_alerts($cpe_id)
{
    $result = DBConnector::getInstance()->getNumThresholdAlerts($cpe_id);
    echo json_encode($result);
}

//Joao Rodrigues - SmartSearch ByZip WS
function get_cpes_zip_by_zip($zip_code){
    $result = DBConnector::getInstance()->getCPEsZipByZip($zip_code);
    echo json_encode($result);
}

//Joao Rodrigues - SmartSearch ByMac WS
function get_cpes_mac_by_mac($mac_address){
    $result = DBConnector::getInstance()->getCPEsMacByMac($mac_address);
    echo json_encode($result);
}

//Joao Rodrigues
function get_cpe_info_by_zip($zip_code){
    $result = DBConnector::getInstance()->getCPEInfoByZip($zip_code);
    echo json_encode($result);
}

//Joao Rodrigues
function get_cpe_info_by_mac($mac_address){
    $result = DBConnector::getInstance()->getCPEInfoByMac($mac_address);
    echo json_encode($result);
}

//Joao Rodrigues
function get_all_cities(){
    $result = DBConnector::getInstance()->getAllCities();
    echo json_encode($result);
}

//Joao Rodrigues
function get_streets_by_city($city){
    $result = DBConnector::getInstance()->getStreetsByCity($city);
    echo json_encode($result);
}

function get_access_by_city($city){
    $result = DBConnector::getInstance()->getAccessByCity($city);
    echo json_encode($result);
}

//Joao Rodrigues
function get_cpes_by_street($street){
    $result = DBConnector::getInstance()->getCPEsByStreet($street);
    echo json_encode($result);
}

//Joao Rodrigues
function get_cpe_full_info($cpe_id){
    $result = DBConnector::getInstance()->getCPEFullInfo($cpe_id);
    echo json_encode($result);
}

/* INITIAL */


require_once '../database/dbconnector.php';

if (isset($_POST['method']))
{
    $method = filter_input(INPUT_POST, 'method');
    if (isset($method))
    {
        switch ($method) 
        {
        case "noise_data_hour":
            return noise_data_hour($_POST['selected_channels'],$_POST['start_time'],$_POST['end_time']);

        // -> Acrescentei aqui
        case "noise_data_minute":
            return noise_data_minute($_POST['selected_channels'],$_POST['start_time'],$_POST['end_time']);

        case "wifi_data_count_hour":
            return wifi_data_count_hour($_POST['start_time'],$_POST['end_time']);

        // -> Acrescentei aqui
        case "wifi_data_count_minute":
            return wifi_data_count_minute($_POST['start_time'],$_POST['end_time']);

        case "wifi_data_count_all_by_day":
            return wifi_data_count_all_by_day();

        case "noise_data_time_bounds":
            return noise_data_time_bounds();

        case "wifi_data_time_bounds":
            return wifi_data_time_bounds();

        case "get_cpes_by_zip":
            return get_cpes_by_zip($_POST['zip_code']);

        case "get_juntas_by_zip":
            return get_juntas_by_zip($_POST['codigo_postal']);

        case "get_num_trehsold_alerts":
            return get_num_trehsold_alerts($_POST['cpe_id']);

        //Joao Rodrigues - SmartSearch ByZip WS
        case "get_cpes_zip_by_zip":
            return get_cpes_zip_by_zip($_POST['zip_code']);

        //Joao Rodrigues - SmartSearch ByMac WS
        case "get_cpes_mac_by_mac":
            return get_cpes_mac_by_mac($_POST['mac_address']);

        //Joao Rodrigues
        case "get_cpe_info_by_zip":
            return get_cpe_info_by_zip($_POST['zip_code']);

        //Joao Rodrigues
        case "get_cpe_info_by_mac":
            return get_cpe_info_by_mac($_POST['mac_address']);

        //Joao Rodrigues
        case "get_all_cities":
            return get_all_cities(); 

        //Joao Rodrigues
        case "get_streets_by_city":
            return get_streets_by_city($_POST['city']);

        case "get_access_by_city":
            return get_access_by_city($_POST['city']);

        //Joao Rodrigues
        case "get_cpes_by_street":
            return get_cpes_by_street($_POST['street']);

        //Joao Rodrigues
        case "get_cpe_full_info":
            return get_cpe_full_info($_POST['cpe_id']);

        }
    } 
}


?>